package com.bjpowernode.web.controller.advice;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice // 对Controller的增强程序，相当于在controller与服务器之间加了一层拦截
public class MyExceptionHandler {
    @ExceptionHandler(NullPointerException.class)
    public String e1(Exception e) {
        return "redirect:/500_spring.jsp";
    }

    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public String e2(Exception e) {
        return "redirect:/500_spring.jsp";
    }
    //...

    // 没有捕获到以上异常，则使用该方法来处理
    @ExceptionHandler(Exception.class)
    public String en(Exception e) {
        return "redirect:/500_spring.jsp";
    }
}
